/*
 * Copyright (C) 2025 SDFX Project
 * SDFX is licensed under Mulan PSL v2.
 */

/**
 * @file log.h
 * @brief SDFX unified logging system
 */

#ifndef SDFX_LOG_H
#define SDFX_LOG_H

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Log level definitions */
#define LOG_LEVEL_ERROR 1
#define LOG_LEVEL_WARN  2
#define LOG_LEVEL_INFO  3
#define LOG_LEVEL_DEBUG 4

/* Default log level */
#ifndef SDFX_LOG_LEVEL
#ifdef DEBUG
#define SDFX_LOG_LEVEL LOG_LEVEL_DEBUG
#else
#define SDFX_LOG_LEVEL LOG_LEVEL_INFO
#endif
#endif

/* Log macro definitions */
#if SDFX_LOG_LEVEL >= LOG_LEVEL_ERROR
#define LOG_ERROR(fmt, ...) printf("[ERROR] " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_ERROR(fmt, ...)
#endif

#if SDFX_LOG_LEVEL >= LOG_LEVEL_WARN
#define LOG_WARN(fmt, ...)  printf("[WARN]  " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_WARN(fmt, ...)
#endif

#if SDFX_LOG_LEVEL >= LOG_LEVEL_INFO
#define LOG_INFO(fmt, ...)  printf("[INFO]  " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_INFO(fmt, ...)
#endif

#if SDFX_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define LOG_DEBUG(fmt, ...) printf("[DEBUG] " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_DEBUG(fmt, ...)
#endif

/* Log macros with module prefix - apply same level filtering */
#if SDFX_LOG_LEVEL >= LOG_LEVEL_ERROR
#define LOG_MODULE_ERROR(module, fmt, ...) printf("[ERROR] " module ": " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_MODULE_ERROR(module, fmt, ...)
#endif

#if SDFX_LOG_LEVEL >= LOG_LEVEL_WARN
#define LOG_MODULE_WARN(module, fmt, ...)  printf("[WARN]  " module ": " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_MODULE_WARN(module, fmt, ...)
#endif

#if SDFX_LOG_LEVEL >= LOG_LEVEL_INFO
#define LOG_MODULE_INFO(module, fmt, ...)  printf("[INFO]  " module ": " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_MODULE_INFO(module, fmt, ...)
#endif

#if SDFX_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define LOG_MODULE_DEBUG(module, fmt, ...) printf("[DEBUG] " module ": " fmt "\n", ##__VA_ARGS__)
#else
#define LOG_MODULE_DEBUG(module, fmt, ...)
#endif

#ifdef __cplusplus
}
#endif

#endif /* SDFX_LOG_H */
